<?php

/**
 * This is the model class for table "emp_persona".
 *
 * The followings are the available columns in table 'emp_persona':
 * @property integer $id
 * @property integer $emp_empresa_id
 * @property string $nombres
 * @property string $apellidos
 * @property string $fe_nac
 * @property string $fe_entrada
 * @property string $doc_identidad
 * @property string $telefono
 * @property string $celular
 * @property string $correo
 * @property string $sexo
 *
 * The followings are the available model relations:
 * @property EmpPerCliente[] $empPerClientes
 * @property EmpEmpresa $empEmpresa
 * @property GlosaPerSexo $sexo0
 * @property EmpPrestador[] $empPrestadors
 */
class EmpPersona extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return EmpPersona the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'emp_persona';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('emp_empresa_id, nombres, apellidos', 'required'),
            array('emp_empresa_id', 'numerical', 'integerOnly' => true),
            array('nombres, apellidos, doc_identidad, telefono, celular, correo', 'length', 'max' => 45),
            array('fe_nac, fe_entrada', 'safe'),
            array('sexo', 'length', 'max' => 1),
            array('correo','email'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, emp_empresa_id, nombres, apellidos, fe_nac, fe_entrada, doc_identidad, telefono, celular, correo', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'empPerClientes' => array(self::HAS_MANY, 'EmpPerCliente', 'emp_persona_id'),
            'sexo0' => array(self::BELONGS_TO, 'GlosaPerSexo', 'sexo'),
            'empEmpresa' => array(self::BELONGS_TO, 'EmpEmpresa', 'emp_empresa_id'),
            'empPrestadors' => array(self::HAS_MANY, 'EmpPrestador', 'emp_persona_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'emp_empresa_id' => 'Empresa',
            'nombres' => 'Nombres',
            'apellidos' => 'Apellidos',
            'fe_nac' => 'Fecha de Nacimiento',
            'fe_entrada' => 'Entrada',
            'doc_identidad' => 'Doc. Identidad',
            'telefono' => 'Teléfono',
            'celular' => 'Teléfono móvil',
            'correo' => 'Correo electrónico',
            'sexo' => 'Sexo',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('emp_empresa', $this->empEmpresa, true);
        $criteria->compare('nombres', $this->nombres, true);
        $criteria->compare('apellidos', $this->apellidos, true);
        $criteria->compare('fe_nac', $this->fe_nac, true);
        $criteria->compare('fe_entrada', $this->fe_entrada, true);
        $criteria->compare('doc_identidad', $this->doc_identidad, true);
        $criteria->compare('telefono', $this->telefono, true);
        $criteria->compare('celular', $this->celular, true);
        $criteria->compare('correo', $this->correo, true);

        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }

}